package com.cherry.androidviewdemo

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.cherry.androidviewdemo.activity.DarrenViewActivity
import com.cherry.androidviewdemo.activity.DrawOrderActivity
import com.cherry.androidviewdemo.activity.LayoutActivity
import com.cherry.androidviewdemo.activity.RecyclerViewActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val list = arrayListOf(Item("绘制顺序", DrawOrderActivity::class.java),
                Item("布局", LayoutActivity::class.java),
                Item("RecyclerView", RecyclerViewActivity::class.java),
                Item("Darren博主源码", DarrenViewActivity::class.java)
        )

        recycler_view.layoutManager = LinearLayoutManager(this)
        val adapter = object : BaseQuickAdapter<Item, BaseViewHolder>(android.R.layout.simple_list_item_1, list) {
            override fun convert(helper: BaseViewHolder, item: Item) {
                helper.setText(android.R.id.text1, item.title)
            }
        }
        recycler_view.adapter = adapter

        adapter.setOnItemClickListener { _, _, position ->
            startActivity(Intent(this, list[position].toActivity))
        }
    }

    data class Item(val title: String, val toActivity: Class<out Activity>)

}
